from django.db import models
from django import forms
from jrcmodel.models import MyConstants, Market
import datetime

DEVIATION_CHOICES = (
    (r"NU", u"Not implemented")
    , (r"SR", u"Faster out")
)

JRC_WORKERS_CHOICES = (
    (r"R", u"R")
    , (r"B", u"B")
    , (r"K", u"K")
    , (r"G", u"G")
    , (r"S", u"S")
)

class RfiPor1(models.Model):
    """ Risk Free Interest for POR1 """
    year = models.IntegerField()
    month = models.IntegerField()
    value = models.DecimalField(max_digits = 10, decimal_places = 4)
    
    def __unicode__(self):
        return "%d-%d: %.14g" % (self.year, self.month, self.value)


class RfiPor3(models.Model):
    """ Risk Free Interest for POR3 """
    year = models.IntegerField()
    month = models.IntegerField()
    value = models.DecimalField(max_digits = 10, decimal_places = 4)
    
    def __unicode__(self):
        return "%d-%d: %.14g" % (self.year, self.month, self.value)

class EuroConvDailyUploadForm(forms.Form):
    year = forms.IntegerField(min_value = 2000, max_value = 2100, widget = forms.Select(choices = [(2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015)]))
    month = forms.IntegerField(min_value = 1, max_value = 12, widget = forms.Select( choices = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11), (12, 12)]))
    textdata = forms.CharField(max_length = 9128, help_text = "Day&nbsp;\\t&nbsp;EURUSD&nbsp;\\t&nbsp;EURJPY&nbsp;\\t&nbsp;EURGBP&nbsp;\\t&nbsp;EURCHF&nbsp;\\t&nbsp;EURAUD&nbsp;\\t&nbsp;EURNZD&nbsp;\\t&nbsp;EURCAD", widget = forms.Textarea(attrs = {"cols": 100, "rows": 30, "style": "font-family: Courier New;"}))

class EuroConvDaily(models.Model):
    status_id = models.IntegerField(default = MyConstants.STATUS_APPROVED, choices = MyConstants.STATUS_CHOICES)
    date = models.DateField(default = datetime.datetime.now)
    
    EURUSD = models.DecimalField(max_digits = 10, decimal_places = 5)
    EURJPY = models.DecimalField(max_digits = 10, decimal_places = 5)
    EURGBP = models.DecimalField(max_digits = 10, decimal_places = 5)
    EURCHF = models.DecimalField(max_digits = 10, decimal_places = 5)
    EURAUD = models.DecimalField(max_digits = 10, decimal_places = 5)
    EURNZD = models.DecimalField(max_digits = 10, decimal_places = 5)
    EURCAD = models.DecimalField(max_digits = 10, decimal_places = 5)
    
    def get_iso_weekday(self):
        """ Returns day of week 1-7 """
        return self.date.weekday() + 1
    
    def __unicode__(self):
        """ Outputs object as string """
        return "%s (%s, %s, %s, %s, %s, %s, %s)" % (self.date, self.EURUSD, self.EURJPY, self.EURGBP, self.EURCHF, self.EURAUD, self.EURNZD, self.EURCAD)

class MyUploadFileForm(forms.Form):
#    title = models.CharField(max_length = 120)
    file = forms.FileField()
        
class Deviation(models.Model):
    status_id = models.IntegerField(default = MyConstants.STATUS_APPROVED, choices = MyConstants.STATUS_CHOICES)
    date = models.DateField()
    market_id = models.ForeignKey(Market)
    category = models.CharField(max_length = 8, choices = DEVIATION_CHOICES)
    initiator = models.CharField(max_length = 8, choices = JRC_WORKERS_CHOICES)
    pl_100 = models.DecimalField(max_digits = 8, decimal_places = 2)
    note = models.CharField(max_length = 256, blank = True)
    